<?php
if(!defined('BLOG'))exit('不作死就不会死');
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2015/1/14
 * Time: 22:38
 */
class index{
    private $db;
    public function __construct(){
        $this->db = base::load_model('comment_model');
    }
    public function save(){

    }
    public function ajax_save(){
        $forminfo = my_addslashes($_POST);
        extract($forminfo);
        if (!@preg_match('/([a-z\d]){2,255}/i', $nickname)) {
            echo json_encode(array(L('nickname_error')));exit;;
        }

        if (!@preg_match('/([a-z\d])+@([a-z\d]){2,15}([\.a-z]){2,6}/',$email)) {
            echo L('email_format_error');
            echo json_encode(array(L('email_format_error')));exit;
            exit;
        }
        if (!@preg_match('/^www\.([a-z\d]+)([\.a-z])(2,6)/', $web)) {
            $web=null;
        }
        $commId=intval($commId);
       /* if ($commId && $commId !=0){
            $where  = ' where id ='.$commId;
            $sql = $this->db->select($where);
            $sendMail  = $this->db->executing($sql);
            $link=$sendMail['url'];
           // $message='<html><head> <title>MYFREAX</title></head><body><p><a href="'.$link.'" target="_bank">有人回复你的回答</a></p></body></html>';
           $Mail=new Mail($sendMail['mail'], WEB_PATH, $message);
            $Mail->sendmail(); //需要配置电子邮件服务器
        }*/
        $url=$url;
        $mail=$email;
        $date=time();
        $articleId=intval($articleId);
        $commcontent=htmlspecialchars($commcontent);  //用户转义html字符串
        preg_match_all('/@(.)+:/iU', $commcontent, $matches);/* 将来发送电子邮件要用 */
        $data = array(
            'nickname' => $nickname,
            'article_id' => $articleId,
            'user_id' => isset($_SESSION['userid'])?$_SESSION['userid']:0,
            'mail' => $email,
            'comment' => $commcontent,
            'web' => $web,
            'url' => '',
            'time' => time(),
            'pid' => $commId,
        );
        $where = ' id ='.$articleId;
        $this->content_db = base::load_model('content_model');
        $var = $this->content_db->update($where, 'comm = comm+1');  //更新文章表中的评论
        $bool = $this->db->insert($data);
        if ($bool) {
            echo json_encode(array(L('comment_saved')));
        }else {
            echo json_encode(array(L('comment_save_fail')));
        }



    }
}